package com.pearadmin.pro.modules.professor.rest;

import com.pearadmin.pro.modules.professor.domain.Professor;
import com.pearadmin.pro.common.aop.annotation.Log;
import com.pearadmin.pro.common.constant.ControllerConstant;
import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import  com.pearadmin.pro.modules.professor.domain.Professor;
import com.pearadmin.pro.modules.professor.dto.ProfessorDTO;
import  com.pearadmin.pro.modules.professor.param.ProfessorRequest;
import  com.pearadmin.pro.modules.professor.service.ProfessorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 教授信息Controller
 *
 * @author ChenJian
 * @date 2021-08-29
 */
@Api(tags = {"教授信息"})
@RestController
@RequestMapping(ControllerConstant.ADMIN+"professor/professor")
public class ProfessorController extends BaseController
{
    @Resource
    private ProfessorService professorService;

    /**
     * 查询教授信息列表
     *  @param request 查询参数
     *  @return {@link Result}
     */
    @GetMapping("/page")
    @Log(title = "教授信息列表")
    @ApiOperation(value = "教授信息列表")
    public Result<Professor> list(ProfessorRequest professorRequest)
    {
        return success(professorService.page(professorRequest));
    }


    /**
     * 新增保存教授信息
     * @param professor 查询参数
     * @return {@link Result}
     */
    @PostMapping("/save")
    @Log(title = "新增教授信息")
    @ApiOperation(value = "新增教授信息")
    public Result save(@RequestBody ProfessorDTO professor)
    {
        return auto(professorService.saveOrUpdate(professor));
    }

    /**
     * 查询教授信息详情
     *
     * @param id 教授信息ID
     * @return 教授信息
     */
    @GetMapping("/selectById")
    @Log(title = "查询教授信息详情")
    @ApiOperation(value = "查询教授信息详情")
    public Result<ProfessorDTO> selectById(@RequestParam Long id)
    {
        return success(professorService.selectProfessorById(id));
    }



    /**
     * 修改保存教授信息
     * @param professor 查询参数
     * @return {@link Result}
     */
    @PutMapping("/update")
    @Log(title = "修改教授信息")
    @ApiOperation(value = "修改教授信息")
    public Result update(@RequestBody ProfessorDTO professor)
    {
        return auto(professorService.saveOrUpdate(professor));
    }


    /**
     * 删除保存教授信息
     * @param id 查询参数
     * @return {@link Result}
     */
    @DeleteMapping("/remove")
    @Log(title = "删除教授信息")
    @ApiOperation(value = "删除教授信息")
    public Result remove(@RequestParam Long id)
    {
        return auto(professorService.removeById(id));
    }

    /**
    * 批量删除教授信息
    * @param ids 批量删除
    * @return {@link Result}
    */
    @DeleteMapping("removeBatch")
    @Log(title = "批量删除教授信息")
    @ApiOperation(value = "批量删除教授信息")
    public Result removeBatch(@RequestParam List<Long> ids){
        return auto(professorService.removeByIds(ids));
    }

}
